package main_com.Controlers.file;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import main_com.mapper.FileMapper;
import main_com.pojo.FileBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.IOException;
import java.util.ArrayList;


@Controller
@RequestMapping("/FileDownController")
public class FileDownController {
    @Autowired
    FileMapper fileMapper;

    @RequestMapping("/fileDown")
    protected void fileDown(HttpServletRequest request, HttpServletResponse response) throws IOException {
        if (request.getServletContext().getAttribute("userName") == null) {
            response.sendRedirect("http://localhost/main");
            return;
        }
        String userName = request.getServletContext().getAttribute("userName").toString();
        ArrayList<FileBean> files = fileMapper.getFileByUserName(userName);
        request.getSession().setAttribute("files", files);
        response.sendRedirect("http://localhost/fileManager/fileDown.jsp");
    }
}
